class CommoncodesController < ApplicationController
  # GET /commoncodes
  # GET /commoncodes.xml
  def index
    @commoncodes = Commoncode.find(:all, :conditions => ["CodeLevel = 0"])
    @mastercode  = Commoncode.find_master_codes
#    @basecode   = Commoncode.find_detail_codes
    @basecode = Commoncode.search(params[:search])
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @commoncodes }
    end
  end

  # GET /commoncodes/1
  # GET /commoncodes/1.xml
  def show
    @commoncode = Commoncode.find(params[:id])
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @commoncode }
    end
  end

  # GET /commoncodes/new
  # GET /commoncodes/new.xml
  def new
    @commoncode = Commoncode.new
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @commoncode }
    end
  end


  # GET /commoncodes/1/edit
  def edit
    @commoncode = Commoncode.find(params[:id])
  end

  # POST /commoncodes
  # POST /commoncodes.xml
  def create
    @commoncode = Commoncode.new(params[:commoncode])
    respond_to do |format|
      if @commoncode.save
        flash[:notice] = 'Commoncode was successfully created.'
        format.html { redirect_to(@commoncode) }
        format.xml  { render :xml => @commoncode, :status => :created, :location => @commoncode }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @commoncode.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /commoncodes/1
  # PUT /commoncodes/1.xml
  def update
    @commoncode = Commoncode.find(params[:id])

    respond_to do |format|
      if @commoncode.update_attributes(params[:commoncode])
        flash[:notice] = 'Commoncode was successfully updated.'
        format.html { redirect_to(@commoncode) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @commoncode.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /commoncodes/1
  # DELETE /commoncodes/1.xml
  def destroy
    @commoncode = Commoncode.find(params[:id])
    @commoncode.destroy

    respond_to do |format|
      format.html { redirect_to(commoncodes_url) }
      format.xml  { head :ok }
    end
  end

  

end

